var JWidget=Base.extend({
  JWidgetOption:{},
    constructor : function(options){
      this.options=options;
    	this.panel=$(document.createElement('div')).addClass('panel').css({width: '250px'}).appendTo($('.edit'));
    	this.core = $(document.createElement("div")).addClass('core').css({width: '150px',height: '150px'}).appendTo($('.edit'));
	   //this.resizeCore();
	   //this.dragCore();
	   //this.resizePanel();
     //this.dragPanel(); 
   },
    resizeCore : function(){
	this.core.resizable();
	this.core.bind("resizestop",function(event,ui){
		alert(ui.size.width+"|"+ui.size.height);
	});
   },
    resizePanel:function(){
	this.panel.resizable();
	this.panel.bind("resizestop",function(event,ui){
		alert(ui.size.width+"|"+ui.size.height);
	});
   },

    dragCore:function(){
  	//this.core.append("<p class='draghandle'>这里拖拽</p>");
	  this.core.draggable({ cursor: 'crosshair',handle:".draghandle",containment:'.edit'});
	  this.core.bind( "dragstop", function(event, ui) {
		alert(ui.position.top+"|"+ui.position.left);
	});
   },
    dragPanel:function(){
  this.panel.draggable({ cursor: 'crosshair',handle:".draghandle",containment:'.edit'});
	this.panel.bind( "dragstop", function(event, ui) {
		alert(ui.position.top+"|"+ui.position.left);
	});
   },

    
    loadCore: function(){},
    loadPanel: function(jClass){
      if($('.settingtitle').length==0)   {

       this.panel.load("/mr8/index.php?r=jwidget/panel/loadPanel"); 
       // this.panel.load("/mr8/index.php?r=jwidget/panel/loadPage");       
      }
      if(jClass!=null){
        var rnd=(new Date().getTime()) ^ Math.random();
        var me=this;
        var $tabs = $( "#tabs").tabs({
            tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
            add: function( event, ui ) {
                $( ui.panel ).load( "/mr8/index.php?r=jwidget/panel/load"+jClass,{widget_id:jClass+rnd,options:this.options} );
            },
            //remove: function(event, ui) { alert("dddd");}
        });

        $tabs.tabs( "add", "#tabs-"+jClass+rnd , "文本" );

         // close icon: removing the tab on click
        // note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924
        $( "#tabs span.ui-icon-close" ).live( "click", function() {
          var index = $( "li", $( "#tabs") ).index( $( this ).parent());
          if(index!=-1)
            $tabs.tabs( "remove", index );
        });
    }
    },
    

    click: function(){},
    init: function(){},
    save: function(){return true;},
    del: function(){return true;}
});
